package poolConexiones.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConexionBD {

	public static Connection obtenerConexion() throws SQLException {

		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost/dew_jfr","root", "123456");
			//con = DriverManager.getConnection("jdbc:mysql://rysmodes.db.7945615.hostedresource.com/rysmodes","rysmodes", "clavedeRex1");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
	
	public static Connection obtenerConexion2() throws SQLException {
		
		 Connection con = null;
		 try {
			 InitialContext initialContext = new InitialContext();
			 DataSource ds = (DataSource)initialContext.lookup("java:comp/env/jdbc/futbolfacil-jfr");
			 con = ds.getConnection();
		
		 } catch (NamingException ex) {
		 	System.out.println(ex.getMessage());
			 throw new SQLException("No se pudo encontrar el DataSource.");
		 } catch (SQLException ex) {
			System.out.println(ex.getMessage());
		 throw new SQLException("No se pudo obtener una conexión.");
		 }
		 return con;

	}
}

